<template>
  <el-dialog
    title="提示"
    :visible.sync="dialogVisible"
    width="80%"
  >
    <div>
      <el-form ref="form" :model="formData" label-width="130px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="数据表登记目录">
              <el-input v-model="formData.tableCatalog" disabled />
            </el-form-item>
            <el-form-item label="数据表登记目录">
              <el-input v-model="formData.tableSchema" disabled />
            </el-form-item>
            <el-form-item label="表名称">
              <el-input v-model="formData.tableName" :disabled="optionType==='see'" />
            </el-form-item>
            <el-form-item label="表类型">
              <el-input v-model="formData.tableType" disabled />
            </el-form-item>
            <el-form-item label="数据库引擎">
              <el-input v-model="formData.engine" disabled />
            </el-form-item>
            <el-form-item label="版本">
              <el-input v-model="formData.version" disabled />
            </el-form-item>
            <el-form-item label="行格式">
              <el-input v-model="formData.rowFormat" disabled />
            </el-form-item>
            <el-form-item label="已存数据行">
              <el-input v-model="formData.tableRows" disabled />
            </el-form-item>
            <el-form-item label="平均行长度">
              <el-input v-model="formData.avgRowLength" disabled />
            </el-form-item>
            <el-form-item label="数据长度">
              <el-input v-model="formData.dataLength" disabled />
            </el-form-item>
            <el-form-item label="注释">
              <el-input v-model="formData.tableComment" :disabled="optionType==='see'" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="索引长度">
              <el-input v-model="formData.indexLength" disabled />
            </el-form-item>
            <el-form-item label="空间碎片">
              <el-input v-model="formData.dataFree" disabled />
            </el-form-item>
            <el-form-item label="自增主键当前值">
              <el-input v-model="formData.autoIncrement" disabled />
            </el-form-item>
            <el-form-item label="创建时间">
              <el-input v-model="formData.createTime" disabled />
            </el-form-item>
            <el-form-item label="更新时间">
              <el-input v-model="formData.updateTime" disabled />
            </el-form-item>
            <el-form-item label="检查时间">
              <el-input v-model="formData.updateTime" disabled />
            </el-form-item>
            <el-form-item label="字符校验编码集">
              <el-input v-model="formData.tableCollation" disabled />
            </el-form-item>
            <el-form-item label="校验和">
              <el-input v-model="formData.checksum" disabled />
            </el-form-item>
            <el-form-item label="创建选项">
              <el-input v-model="formData.createOptions" disabled />
            </el-form-item>
            <el-form-item label="最大数据长度">
              <el-input v-model="formData.maxDataLength" disabled />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <div v-if="optionType==='edit'">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </div>
      <el-button v-else type="primary" @click="close">关 闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getById, updateById } from '@/api/code-generate/table'

export default {
  name: 'Edit',
  data() {
    return {
      optionType: '',
      dialogVisible: false,
      infoData: {},
      tableName: null,
      formData: {},
      oldTableName: null
    }
  },
  methods: {
    open(optionType, tableName) {
      this.optionType = optionType
      this.tableName = tableName
      this.dialogVisible = true
      this.getByIdData()
    },
    close() {
      this.formData = {}
      this.dialogVisible = false
    },
    save() {
      updateById({
        oldTableName: this.oldTableName,
        newTableName: this.formData.tableName,
        tableComment: this.formData.tableComment
      }).then(res => {
        this.$message.success('修改成功')
        this.close()
        this.$emit('refreshPageData')
      })
    },
    getByIdData() {
      getById(this.tableName).then(res => {
        this.formData = res.obj
        this.oldTableName = res.obj.tableName
      })
    }
  }
}
</script>

<style scoped>

</style>
